######################################################/
## Anticipated Election Result and Protest Voting    ##
## -- Replication Material (Master File)             ##
## by: Christian Schimpf                             ##
## Version: July 01, 2019                            ##
## R-Version: 3.4.0.                                 ##
######################################################/

# This File Runs all R-Scripts related to the paper 
# "Anticipated election result and protest voting: why and when Canadian
# voters signal discontent" published in the Canadian Journal of Political
# Science (Online First in 2019)

# There are three R-Scripts that can be called and run from this Master File
# (provided all paths specified in the files are adjusted accordingly):
# 1. CJPS_Schimpf_Replication_DataPrep1_20190107.R (Is used to generate a dataset
#    based on the original Making Electoral Democracy Work datasets - see READ ME File
#    for more explanations)
# 2. CJPS_Schimpf_Replication_DataPrep2_20190107.R (Used to derive all variables used
#    in the main analyses and the robustness checks in the Online Supplementary Files)
# 3. CJPS_Schimpf_Replication_Analyses_20190107.R (Used to generate all descriptive
#    statistics, Figures, main regression analyses, and robustness checks reported in
#    the online appendix).

# The first R-Script can only be run after downloading three separate datasets from the 
# Harvard Dataverse Making Electoral Democracy Work website:
# Cross, William; G�lineau, Fran�ois; Gidengil, Elisabeth; Pruysers, Scott; Andrea, Lawlor; 
# Blais, Andr�; Stephenson, Laura, 2017, "MEDW 2015 Canadian Federal Election Study", 
# https://doi.org/10.7910/DVN/ITIJT0 , 
# Harvard Dataverse, V1, UNF:6:JuosJ+68xEwFwPlp7EiMlw== [fileUNF] 
# https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/ITIJT0
# (Last accessed: July 1, 2019)
#
# The files to be downloaded are:
# British_Columbia_federal_2015.dta
# Ontario_federal_2015.dta
# Quebec_federal_2015.dta

# For the purpose of this project, the files were last downloaded on Mach 3, 2018. Any changes 
# being made to the original files may thus lead to differences. 
#
# The analysis can also be replicated, using only RScripts two and three since the first R-Script
# was used to generate a dataset based on the three separate original datasets with variables of
# interest ("dfCan2015.RData"). For replication purposes, however, it should suffice to use the 
# dataset "dfCan2015.RData" and run R-Script 2 and R-Script 3. 


## Good luck!


#Clear the working space
rm(list=ls()) 

#############################################################/
#### >>> Set working directory                           ####
#############################################################/

setwd("<FOLDER>/CJPS Replication Material")



#############################################################/
#### >>> Run scripts                                    ####
#############################################################/

#source("./CJPS_Schimpf_Replication_DataPrep1_20190107.R", verbose=F)   ## Generates joint dataset based on original MEDW data
source("./CJPS_Schimpf_Replication_DataPrep2_20190107.R", verbose=F)   ## Includes recodes and deriving variables used in analyses
source("./CJPS_Schimpf_Replication_Analyses_20190107.R", verbose=F)   ## Runs main analyses 

